<?php
function __autoload($class_name) {
    include '../class/' . $class_name . '.php';
}
?>
<?php include("functions.php"); ?>
<?php include("connection.php"); ?>

<?php
	if (isset($_GET['id']) && isset($_GET['p']) && isset($_GET['s']) && isset($_GET['v'])) {
		$q = "UPDATE statistika SET ".$_GET['s']." = ".$_GET['s']." ".sprintf('%+d', ($_GET['v']))." WHERE igrac = ".$_GET['p']." AND mec = ".$_GET['id'];
		mysql_query($q);
	}
?>
<?php
	$mec = new Match($_GET['id']);
	
	$mec->domacin->getRoster();
	$mec->gost->getRoster();
	
	$mec->domacin->stats = $mec->domacin->getMatchStats($mec->id);
	$mec->gost->stats = $mec->gost->getMatchStats($mec->id);
	
?>


        	<div class="fullPageBox">
            	<div class="scoreboard">
                	<div class="scoreboardTop">
                    	<div class="homeTeam"><a href="team/<?php echo $mec->domacin->id; ?>/<?php echo $mec->domacin->ime; ?>"><?php echo $mec->domacin->ime; ?></a></div>
                    	<div class="awayTeam"><a href="team/<?php echo $mec->gost->id; ?>/<?php echo $mec->gost->ime; ?>"><?php echo $mec->gost->ime; ?></a></div>
                    </div>
                    
                    <div class="scoreboardResult">
                    	<div class="homeLogo"><img src="media/teams/logo/<?php echo $mec->domacin->grb; ?>" height="100" /></div>
                        <div class="scoreboardScore"><?php echo $mec->domacin->stats->pts; ?> - <?php echo $mec->gost->stats->pts; ?></div>
                    	<div class="awayLogo"><img src="media/teams/logo/<?php echo $mec->gost->grb; ?>" height="100" /></div>
                    </div>
                    
                    <div class="scoreboardTeamStats">
                    	<div class="scoreboardStat statsOdd">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->ft; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->ft, $mec->gost->stats->ft); ?>px 0">Free Throws</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->ft; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->fg; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->fg, $mec->gost->stats->fg); ?>px 0">Field Goals</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->fg; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->threept; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->threept, $mec->gost->stats->threept); ?>px 0">3-Pointers</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->threept; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->drbd; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->drbd, $mec->gost->stats->drbd); ?>px 0">Defensive Rebounds</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->drbd; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->orbd; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->orbd, $mec->gost->stats->orbd); ?>px 0">Offensive Rebounds</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->orbd; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->totalRbd; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->totalRbd, $mec->gost->stats->totalRbd); ?>px 0">Total Rebounds</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->totalRbd; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->blk; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->blk, $mec->gost->stats->blk); ?>px 0">Blocks</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->blk; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->ast; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->ast, $mec->gost->stats->ast); ?>px 0">Assists</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->ast; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->stl; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->stl, $mec->gost->stats->stl); ?>px 0">Steals</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->stl; ?></div>
                        </div>
                    	<div class="scoreboardStat">
                        	<div class="scoreHome"><?php echo $mec->domacin->stats->licne; ?></div>
                            <div class="scoreName" style="background-position:<?php echo calculateBgWidth($mec->domacin->stats->licne, $mec->gost->stats->licne); ?>px 0">Fouls</div>
                            <div class="scoreAway"><?php echo $mec->gost->stats->licne; ?></div>
                        </div>
                    </div>
                </div>
            </div><!-- end of scoreboard -->
                        
            <div class="twoCollumns">
            	<div class="leftCollumn">
                
                	<div class="leftBox">
                    	<table class="tabela teamStatistics" cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                            	<td>#</td>
                            	<td></td>
                            	<td class="statsPlayerName">Player</td>
                            	<td>PTS</td>
                            	<td>FT</td>
                            	<td>MFT</td>
                            	<td>2PT</td>
                            	<td>M2P</td>
                            	<td>3PT</td>
                            	<td>M3P</td>
                            	<td>ASS</td>
                            	<td>DRB</td>
                            	<td>ORB</td>
                            	<td>BLK</td>
                            	<td>STL</td>
                            	<td>FLS</td>
                            </tr>
                        </thead>
                        <tbody>
                        	<?php
								foreach ($mec->domacin->roster as $igrac) {
									$igrac->getStats($mec->id);
							?>
                        	<tr>
                            	<td class="statsOdd"><?php echo $igrac->dres; ?></td>
                            	<td class="statsOdd"><img src="media/players/<?php echo $igrac->slika; ?>" width="30" /></td>
                            	<td class="statsPlayerName"><a href="player/<?php echo $igrac->id; ?>/<?php echo $igrac->ime; ?>-<?php echo $igrac->prezime; ?>"><?php echo $igrac->ime; ?> <?php echo $igrac->prezime; ?></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->pts; ?></td>
                            	<td><?php echo $igrac->stats[$mec->id]->ft; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=ft&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=ft&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                                </td>
                            	<td><?php echo $igrac->stats[$mec->id]->mft; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=mft&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=mft&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                                </td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->fg; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=fg&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=fg&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->mfg; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=mfg&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=mfg&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->threept; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=3pt&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=3pt&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->mtp; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=m3p&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=m3p&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->ast; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=ast&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=ast&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->drbd; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=drbd&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=drbd&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->orbd; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=orbd&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=orbd&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->blk; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=blk&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=blk&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->stl; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=stl&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=stl&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->licne; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=licne&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=licne&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            </tr>
                        	<?php
								}
							?>
                        </tbody>
                        </table>
                    </div>
                    <h3 class="smallBoxTitle"><a href="#">Home Statistics</a></h3>
                    
                	<div class="leftBox">
                    	<table class="tabela teamStatistics" cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                            	<td>#</td>
                            	<td></td>
                            	<td class="statsPlayerName">Player</td>
                            	<td>PTS</td>
                            	<td>FT</td>
                            	<td>MFT</td>
                            	<td>2PT</td>
                            	<td>M2P</td>
                            	<td>3PT</td>
                            	<td>M3P</td>
                            	<td>ASS</td>
                            	<td>DRB</td>
                            	<td>ORB</td>
                            	<td>BLK</td>
                            	<td>STL</td>
                            	<td>FLS</td>
                            </tr>
                        </thead>
                        <tbody>
                        	<?php
								foreach ($mec->gost->roster as $igrac) {
									$igrac->getStats($mec->id);
							?>
                        	<tr>
                            	<td class="statsOdd"><?php echo $igrac->dres; ?></td>
                            	<td class="statsOdd"><img src="media/players/<?php echo $igrac->slika; ?>" width="30" /></td>
                            	<td class="statsPlayerName"><a href="player/<?php echo $igrac->id; ?>/<?php echo $igrac->ime; ?>-<?php echo $igrac->prezime; ?>"><?php echo $igrac->ime; ?> <?php echo $igrac->prezime; ?></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->pts; ?></td>
                            	<td><?php echo $igrac->stats[$mec->id]->ft; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=ft&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=ft&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                                </td>
                            	<td><?php echo $igrac->stats[$mec->id]->mft; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=mft&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=mft&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                                </td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->fg; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=fg&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=fg&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->mfg; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=mfg&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=mfg&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->threept; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=3pt&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=3pt&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->mtp; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=m3p&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=m3p&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->ast; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=ast&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=ast&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->drbd; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=drbd&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=drbd&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->orbd; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=orbd&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=orbd&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->blk; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=blk&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=blk&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td class="statsOdd"><?php echo $igrac->stats[$mec->id]->stl; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=stl&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=stl&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            	<td><?php echo $igrac->stats[$mec->id]->licne; ?><br />
                                	<a class="but minus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=licne&amp;v=-1', 'page');"><img src="template/images/minus.png" /></a>
                                    <a class="but plus" href="javascript:ajaxpage('components/showMatch.php?id=<?php echo $mec->id; ?>&amp;p=<?php echo $igrac->id; ?>&amp;s=licne&amp;v=1', 'page');"><img src="template/images/plus.png" /></a></td>
                            </tr>
                        	<?php
								}
							?>
                        </tbody>
                        </table>
                    </div>
                    <h3 class="smallBoxTitle"><a href="#">Away Statistics</a></h3>
                                        
                </div>
                
                <div class="rightCollumn">
                </div>
                    
